package jp.ac.waseda.cs.washi.game.factory;

import java.io.*;
import java.net.URL;
import java.util.ArrayList;

public class FileLineReader {
	public ArrayList<String> read(String fileName) throws IllegalArgumentException {
		ArrayList<String> result = new ArrayList<String>();
		FileInputStream fis = null;
		BufferedReader br = null;
		try {
			URL url = getClass().getClassLoader()
				.getResource("map/" + fileName);
			br = new BufferedReader(new InputStreamReader(url.openStream()));
			String line;
			while ((line = br.readLine()) != null) {
				result.add(line);
			}
			return result;
		} catch (FileNotFoundException e) {
			throw new IllegalArgumentException();
		} catch (IOException e) {
			throw new IllegalArgumentException();
		} finally {
			if (fis != null) {
				try {
					fis.close();
				} catch (IOException e) {
				}
			}
			if (br != null) {
				try {
					br.close();
				} catch (IOException e) {
				}
			}
		}
	}
}
